package com.v2future.sjt.collegecheckingattendance.utils;

import android.content.ContentResolver;
import android.content.Context;
import android.database.Cursor;
import android.os.Handler;
import android.provider.ContactsContract;
import android.provider.ContactsContract.PhoneLookup;
import android.text.format.Time;
import android.view.View;
import android.view.WindowManager;
import android.view.inputmethod.InputMethodManager;
import android.widget.EditText;

import com.v2future.sjt.collegecheckingattendance.MainActivity;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

/**
 * The type Phone util.
 */
public class PhoneUtil {


    /**
     * 格式化手机号码，去掉-和空格
     *
     * @param mobile
     *         the mobile
     *
     * @return string string
     */
    public static String formatMobile(String mobile) {
        String result = mobile;
        try {
            result = result.replace(" ", "");
            result = result.replace("-", "").trim();
        } catch (Exception e) {
            // TODO: handle exception
        }
        return result;
    }

    /**
     * 显示/隐藏输入法 暂时未实现显示输入法的功能
     *
     * @param context
     *         TTSActivity实例
     * @param et
     *         the et
     * @param visibility
     *         the visibility
     */
    public static void setInputVisibility(Context context, EditText et, int visibility) {

        InputMethodManager imm = (InputMethodManager) context.getSystemService(Context
                .INPUT_METHOD_SERVICE);
        if (View.GONE == visibility) {//设置为不显示
            if (((MainActivity) context).getWindow().getAttributes().softInputMode
                    == WindowManager.LayoutParams.SOFT_INPUT_STATE_UNSPECIFIED) {
//    			 imm.toggleSoftInput(0, InputMethodManager.HIDE_NOT_ALWAYS);
                imm.hideSoftInputFromWindow(et.getWindowToken(), 0);
            }

        } else if (View.VISIBLE == visibility) {//显示输入法

        }
    }

    /**
     * 获取手机当前时间
     *
     * @return current date time
     */
    public static String getCurrentDateTime() {
        Time t = new Time(); // or Time t=new Time("GMT+8"); 加上Time Zone资料。
        t.setToNow(); // 取得系统时间。
        int year = t.year;
        int month = t.month + 1;
        int date = t.monthDay;
        int hour = t.hour; // 0-23
        int minute = t.minute;
        int second = t.second;
        return year + "-" + month + "-" + date + " " + hour + ":" + minute + ":" + second;
    }

    /**
     * 根据手机的分辨率从 dp 的单位 转成为 px(像素)
     *
     * @param context
     *         the context
     * @param dpValue
     *         the dp value
     *
     * @return the int
     */
    public static int dip2px(Context context, float dpValue) {
        final float scale = context.getResources().getDisplayMetrics().density;
        return (int) (dpValue * scale + 0.5f);
    }

    /**
     * 根据手机的分辨率从 px(像素) 的单位 转成为 dp
     *
     * @param context
     *         the context
     * @param pxValue
     *         the px value
     *
     * @return the int
     */
    public static int px2dip(Context context, float pxValue) {
        final float scale = context.getResources().getDisplayMetrics().density;
        return (int) (pxValue / scale + 0.5f);
    }

    /**
     * The type Contact.
     */
    public static class Contact implements Serializable {
        /** The Name. */
        private String name;
        /** The Sort key. */
        private String sortKey;
        /** The Mobiles. */
        private List<String> mobiles;
        /** The Show detail. */
        private boolean showDetail;//多手机号是否显示详情

        /**
         * Gets sort key.
         *
         * @return the sort key
         */
        public String getSortKey() {
            return sortKey;
        }

        /**
         * Sets sort key.
         *
         * @param sortKey
         *         the sort key
         */
        public void setSortKey(String sortKey) {
            this.sortKey = sortKey;
        }

        /**
         * Gets name.
         *
         * @return the name
         */
        public String getName() {
            return name;
        }

        /**
         * Sets name.
         *
         * @param name
         *         the name
         */
        public void setName(String name) {
            this.name = name;
        }

        /**
         * Gets mobiles.
         *
         * @return the mobiles
         */
        public List<String> getMobiles() {
            return mobiles;
        }

        /**
         * Sets mobiles.
         *
         * @param mobiles
         *         the mobiles
         */
        public void setMobiles(List<String> mobiles) {
            this.mobiles = mobiles;
        }

        /**
         * Is show detail boolean.
         *
         * @return the boolean
         */
        public boolean isShowDetail() {
            return showDetail;
        }

        /**
         * Sets show detail.
         *
         * @param showDetail
         *         the show detail
         */
        public void setShowDetail(boolean showDetail) {
            this.showDetail = showDetail;
        }

    }
}
